package com.example.util;

import org.springframework.stereotype.Component;

import java.security.SecureRandom;

/**
 * 公共工具类
 * 
 */
@Component
public class CommonUtils {

    /**
     * 生成随机字符串（使用默认字符集：A-Z, a-z, 0-9）
     * @param length 字符串长度
     * @return 随机字符串
     */
    public String generateRandomString(int length) {
        String chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
        SecureRandom random = new SecureRandom();
        StringBuilder result = new StringBuilder();
        
        for (int i = 0; i < length; i++) {
            result.append(chars.charAt(random.nextInt(chars.length())));
        }
        
        return result.toString();
    }

}
